<?php

namespace Admin\Models\faq;

use Admin\Models\BaseModel;
class XhfaqInfo extends BaseModel
{

    /**
     *
     * @var integer
     */
    public $iFAQId;

    /**
     *
     * @var string
     */
    public $iAppCode;

    /**
     *
     * @var string
     */
    public $sQuestion;

    /**
     *
     * @var string
     */
    public $mAnswer;

    /**
     *
     * @var integer
     */
    public $iOrderCode;

    /**
     *
     * @var integer
     */
    public $iType;

    /**
     *
     * @var integer
     */
    public $iUserType;

    /**
     *
     * @var integer
     */
    public $iFaqType;

    /**
     *
     * @var integer
     */
    public $bDelete;

    /**
     *
     * @var string
     */
    public $tCreateDate;

    /**
     *
     * @var string
     */
    public $iCreateUserId;

    /**
     *
     * @var string
     */
    public $tLastModifyDate;

    /**
     *
     * @var string
     */
    public $iLastModifyUserId;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        parent::initialize();
        $this->setSource("XHFaq_Info");
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHFaq_Info';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhfaqInfo[]
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhfaqInfo
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * 根据传入id，删除对应记录并返回删除结果
     *
     * @param $ids
     * @return mixed
     *
     * create by ck 20160924
     */
    public static function deleteRecordById($ids){
        return self::find(array(
            'conditions' => "iFAQId IN ({$ids}) AND bDelete = 0"
        ))->delete();
    }

    /**
     * 根据数据编辑相应model
     *
     * @param  $data
     * @return XhfaqInfo
     *
     * create by ck 20160713
     */
    public static function createRecord($data)
    {
        $obj = $data['iFAQId'] ? self::findFirst($data['iFAQId']) : new self;
        $obj->assign($data);
        return $obj;
    }

}
